<template>
  <h1>this is test.vue</h1>
  <button @click="onClick">login</button>
</template>

<script lang="ts">
import { ref, reactive } from "vue";
import { register, login } from "@/api/user";
import store from "@/store/index";

import axios from "axios"; // 引入axios

export default {
  name: "Test",
  setup() {
    async function onClick() {
      console.log("login");
      try {
        let token = await store.dispatch("login", {
          name: "admin",
          password: "admin12345",
        });
        console.log(23333333333333);
      } catch (e) {
        console.log("fail", e);
      }
    }
    return {
      onClick,
    };
  },
  // 挂载的时候获取新闻列表
  mounted() {
    axios.get("/mock/news").then((res) => {
      // url即在mock.js中定义的
      console.log(res.data); // 打印一下响应数据
    });
  },
};
</script>

<style>
</style>